<template>
	<view>
		<!-- 渲染收货信息的盒子 -->
		<view class="address-choose-box">
			<navigator url="/subpkg/addressadd/addressadd" hover-class="navigator-hover">
				<button size="mini" class="btnChooseAddress">添加收货地址+</button>
			</navigator>
		</view>
		<view class="address-info-box" v-for="(item) in addressList">
			<view class="row1">
				<view class="row1-left">
					<view class="username">收货人：<text>{{item.userName}}</text></view>
				</view>
				<view class="row1-right">
					<view class="phone">电话：<text>{{item.phone}}</text></view>
					<uni-icons type="compose" size="20" @click="(event) => onClick(event, item)"></uni-icons>
				</view>
			</view>
			<view class="row2">
				<view class="row2-left">收货地址：</view>
				<view class="row2-right">
					<text>{{item.addressName}}</text>
					<text v-if="item.isDefault" style="color: #ffaa00; font-weight: bold;">（默认）</text>
					<!-- <button type="primary" size="mini" @click="setDefaultAddress(item.addressId)">设为默认</button> -->
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';

	export default {
		computed: {
			// 从 m_user 模块中导入需要的对象
			...mapState('m_user', ['userId']),

		},
		data() {
			return {
				addressList: []
			};
		},
		onLoad() {
			this.getAddresslist();
		},
		methods: {
			async getAddresslist() {
				try {
					const res = await uni.$http.get(`/wx/addresslist/${this.userId}`);
					this.addressList = res.data.data
					console.log(res.data.data)
				} catch (e) {
					console.log(e)
				}
			},
			onClick(event, item) {
				
					uni.navigateTo({
						url: `/subpkg/addressedit/addressedit?addressId=${item.addressId}&userId=${item.userId}`
					});
			}
			// async editCanle() {
			// 	try {
			// 		const res = await uni.$http.get(`/wx/addresslist/${this.addressList.adressId}`);
			// 	} catch (e) {

			// 	}
			// }
		}
	}
</script>

<style lang="scss">
	// 底部边框线的样式
	.address-border {
		display: block;
		width: 100%;
		height: 5px;
	}

	// 选择收货地址的盒子
	.address-choose-box {
		height: 50px;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	// 渲染收货信息的盒子
	.address-info-box {
		background: #fff;
		font-size: 12px;
		height: 90px;
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding: 0 10px;
		// margin: 5px;
		// border-radius: 10px;
		border-bottom: 1px solid #aaa6a6;

		// 第一行
		.row1 {
			display: flex;
			justify-content: space-between;

			.row1-right {
				display: flex;
				align-items: center;

				.phone {
					margin-right: 25px;
				}
			}
		}

		// 第二行
		.row2 {
			display: flex;
			align-items: center;
			margin-top: 10px;

			.row2-left {
				white-space: nowrap;
			}
		}
	}
</style>